package com.ruoyi.safe.controller.web;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.safe.domain.BizOrgImg;
import com.ruoyi.safe.service.IBizOrgImgService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 组织机构图Controller
 * 
 * @author ruoyi
 * @date 2023-12-13
 */
@RestController
@RequestMapping("/img/img")
public class BizOrgImgController extends BaseController
{
    @Autowired
    private IBizOrgImgService bizOrgImgService;

    /**
     * 查询组织机构图列表
     */
    @PreAuthorize("@ss.hasPermi('img:img:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizOrgImg bizOrgImg)
    {
        startPage();
        List<BizOrgImg> list = bizOrgImgService.selectBizOrgImgList(bizOrgImg);
        return getDataTable(list);
    }

    /**
     * 导出组织机构图列表
     */
    @PreAuthorize("@ss.hasPermi('img:img:export')")
    @Log(title = "组织机构图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizOrgImg bizOrgImg)
    {
        List<BizOrgImg> list = bizOrgImgService.selectBizOrgImgList(bizOrgImg);
        ExcelUtil<BizOrgImg> util = new ExcelUtil<BizOrgImg>(BizOrgImg.class);
        util.exportExcel(response, list, "组织机构图数据");
    }

    /**
     * 获取组织机构图详细信息
     */
    @PreAuthorize("@ss.hasPermi('img:img:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizOrgImgService.selectBizOrgImgById(id));
    }

    /**
     * 新增组织机构图
     */
    @PreAuthorize("@ss.hasPermi('img:img:add')")
    @Log(title = "组织机构图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizOrgImg bizOrgImg)
    {
        return toAjax(bizOrgImgService.insertBizOrgImg(bizOrgImg));
    }

    /**
     * 修改组织机构图
     */
    @PreAuthorize("@ss.hasPermi('img:img:edit')")
    @Log(title = "组织机构图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizOrgImg bizOrgImg)
    {
        return toAjax(bizOrgImgService.updateBizOrgImg(bizOrgImg));
    }

    /**
     * 批量修改
     * @param bizOrgImgList
     * @return
     */
    @PutMapping("/imgList")
    public AjaxResult updateList(@RequestBody List<BizOrgImg> bizOrgImgList){
        return toAjax(bizOrgImgService.updateBizOrgImgList(bizOrgImgList));
    }

    /**
     * 删除组织机构图
     */
    @PreAuthorize("@ss.hasPermi('img:img:remove')")
    @Log(title = "组织机构图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizOrgImgService.deleteBizOrgImgByIds(ids));
    }
}
